using System;
using System.Collections.Generic;
using System.Text;
using XinBang.Entity;
using XinBang.DAL;

namespace XinBang.BLL
{
    public class GoodsCatalogBL
    {
        private IGoodsCatalogDA<GoodsCatalog> gcda = BusinessLogicFactory.GetGoodsCatalogDA();
        
        public GoodsCatalog GetCatalogById(int p)
        {
            return gcda.Get(p);
        }

        public void SaveCatalog(GoodsCatalog gc)
        {
            gcda.Insert(gc);
        }

        public void UpdateCatalog(GoodsCatalog gc)
        {
            gcda.Update(gc);
        }

        public IList<GoodsCatalog> GetAllCatalogs()
        {
            IList<GoodsCatalog> list = gcda.GetAllCatalogs();
            foreach (GoodsCatalog gc in list)
            {
                if (gc.Level == 2)
                {
                    gc.CatalogName = "&nbsp;&nbsp;&nbsp;&nbsp;" + gc.CatalogName;
                }
            }
            return list;
        }

        public IList<GoodsCatalog> GetAllFirstCatalogs()
        {
            return gcda.GetAllFirstCatalogs();
        }

        public void DeleteCatalog(GoodsCatalog gc)
        {
            gcda.Delete(gc);
        }

        public GoodsCatalog GetCatalogByName(string p)
        {
            return gcda.GetCatalogByName(p);
        }

        public IList<GoodsCatalog> GetSecondCatalogsByParentId(int p)
        {
            return gcda.GetSecondCatalogsByParentId(p);
        }
    }
}
